package com.singzi.leetcode.N100;

public class T0006 {
    public static void main(String[] args) {
        Solution0006 solution0006 = new Solution0006();
        System.out.println(solution0006.convert("PAYPALISHIRING", 4));
    }
}

class Solution0006 {
    public String convert(String s, int numRows) {

        int n = s.length();
        int j = 0;
        int flag = 0;
        String []a = new String[numRows];
        for(int i = 0;i < numRows;i++){
            a[i]="";
        }
        while(j<n){
            // if(i == numRows-1) flag = 1;
            switch(flag){
                case 0:{
                    for(int i = 0;i < numRows;i++){
                        if(j>=n) break;
                        a[i] = a[i]+s.charAt(j);
                        j++;
                    }
                    flag = 1;
                }
                case 1:{
                    for(int i = numRows-2;i >= 1;i--){
                        if(j>=n) break;
                        a[i] = a[i]+s.charAt(j);
                        j++;
                    }
                    flag = 0;
                }
            }

        }
        String result = new String();
        result = "";
        for(int i = 0;i < numRows;i++){
            result = result+a[i];
        }
        return result;
    }
}
